<?php
$section = "member";
$titre = _LB_BOOKING_ADJUSTMENT;
$link = $section;
if(isMemberLoggedIn()){
	redirect(APPLICATION_URL_FO."/");
}
//get object ID
$id = Request::getIntNumber('id');
$act = Request::getIntNumber('act');

//get back link
$backlink = Session::getBackLink($section,"list/?");

$member = new Member();
if($id)
{
	if(!$member->get($id))
		redirect($backlink);
}

//if action = UPDATE or CREATE
if ($act == ACT_VALID_EDIT)
{
	$member->FIRST_NAME = trim(Request::get('FIRST_NAME'));
    $member->LAST_NAME = trim(Request::get('LAST_NAME'));
    $member->EMAIL = trim(Request::get('EMAIL'));
    $member->PHONE = trim(Request::get('PHONE'));
    $member->DISABLED = Request::getNumber('DISABLED');
    $member->NEWSLETTER = Request::getNumber('NEWSLETTER');
    
	if ($member->validateInput())
	{
		if(!$member->ID){
            $member->PASS = sha1(Request::get("PASS"));
			$member->insert();
			if(isset($_SESSION['bookingData']) && $_SESSION['bookingData'] != "" && is_array(unserialize($_SESSION['bookingData']))){
				$_SESSION['memberID'] = $member->ID;
				redirect(APPLICATION_URL_FO."/booking/preview/");
			}
        }
		else{
			$member->update();
        }
		redirect(APPLICATION_URL_FO."/page/thanks_registration/");
	}

}

//create cfer
$cfer = new Cfer(array(
	_LB_ACCUEIL => APPLICATION_URL_FO,
	_LB_BOOKING_ADJUSTMENT => $backlink));

//if validate is false, display form again
$smarty->assign('cfer', $cfer);
$smarty->assign('member', $member);
$smarty->assign('backlink', $backlink);
$smarty->display('member_register.html');

